﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Common.UI.EM.Views.Interfaces;
using Common.Model;
using Microsoft.Windows.Controls;

namespace Common.UI.EM.Views
{
    /// <summary>
    /// Interaction logic for ListView.xaml
    /// </summary>
    public partial class ListView : UserControl, IListView
    {

        Object _model;
        public Object Model
        {
            get
            {
                return _model;
            }
            set
            {
                _model = value;
                this.DataContext = _model;
            }
        }

        public ListView()
        {
            InitializeComponent();
        }

        #region IListView Members

        public Common.Model.ViewEntity GetSelectedEntity()
        {
            if (this.listDataGrid.SelectedItem == null)
            {
                MessageBox.Show("Debe seleccionar al menos un item de la grilla.", "Atención", MessageBoxButton.OK);
                return null;
            }

            return this.listDataGrid.SelectedItem as ViewEntity;
        }

        public void AddColumnDefinition(String columnName, String header)
        {
            var column = new DataGridTextColumn();

            column.Header = header;
            column.Binding = new Binding(columnName);
            column.IsReadOnly = true;
            this.listDataGrid.Columns.Add(column);
        }

        #endregion

    }
}
